unit FZScreen;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TFormFZScreen = class(TForm)
    Label1: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FPanelList : TList;
    //FMonitorIndex: Integer;
    function GetPanelCount: Integer;
    function GetPanel(AIndex: Integer): TPanel;
    //procedure SetMonitorIndex(const Value: Integer);
  public
    { Public declarations }
    function AddPanel:TPanel;
    procedure ResizePanel;
    property PanelCount : Integer  read GetPanelCount;
    property Panels[AIndex : Integer] : TPanel read GetPanel;
    //property MonitorIndex : Integer  read FMonitorIndex write SetMonitorIndex;
  end;

  TFZScreenList = class(TList)
  private
    FOwner : TComponent;

    function Get(Index: Integer): TFormFZScreen;
    procedure Put(Index: Integer; const Value: TFormFZScreen);
  protected
    procedure Notify(Ptr: Pointer; Action: TListNotification); override;
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy; override;
    function Add:TFormFZScreen;
    property Items[Index: Integer]: TFormFZScreen read Get write Put; default;
  end;

var
  FormFZScreen: TFormFZScreen;

implementation

{$R *.dfm}

procedure TFormFZScreen.FormShow(Sender: TObject);
begin
//  ResizePanel;
end;

procedure TFormFZScreen.FormResize(Sender: TObject);
begin
//  ResizePanel;
end;

procedure TFormFZScreen.FormCreate(Sender: TObject);
begin
//  FPanelList := TList.Create;
//  FMonitorIndex := 0;
end;

procedure TFormFZScreen.FormDestroy(Sender: TObject);
var
  i : Integer;
begin
//  For i := 0 to PanelCount -1 do
//    TPanel(FPanelList.Items[i]).Free;

//  FPanelList.Free;
end;

function TFormFZScreen.GetPanelCount: Integer;
begin
//  Result := FPanelList.Count;
end;

function TFormFZScreen.AddPanel: TPanel;
begin
{  Result := TPanel.Create(Self);
  Result.Parent := Self;
  Result.Name := Format('Panel%d',[PanelCount]);
  FPanelList.Add(Result);
  ResizePanel;
  }
end;

procedure TFormFZScreen.ResizePanel;
var
  i,iWidth : Integer;
begin
  if PanelCount=0 then Exit;

  iWidth := Self.Width div PanelCount;
  for i := 0 to PanelCount -1 do
  begin
    TPanel(FPanelList.Items[i]).Left := iWidth * i ;
    TPanel(FPanelList.Items[i]).Width := iWidth;
  //  if i = PanelCount -1 then
  //    TPanel(FPanelList.Items[i]).Align := alClient
  //  else
      TPanel(FPanelList.Items[i]).Align := alLeft;

  end;
end;

function TFormFZScreen.GetPanel(AIndex: Integer): TPanel;
begin
  if (AIndex>-1) and (AIndex < PanelCount) then
    Result := TPanel(FPanelList.Items[AIndex]);
end;
{
procedure TFormFZScreen.SetMonitorIndex(const Value: Integer);
var
  i : Integer;
begin
  FMonitorIndex := Value;
  
  i := 0;
  if Screen.MonitorCount>FMonitorIndex then
    i := FMonitorIndex;
  Left := Screen.Monitors[i].Left;
  Top :=Screen.Monitors[i].Top;
  Width:=Screen.Monitors[i].Width;
  Height:=Screen.Monitors[i].Height;

end;
}
{ TFZScreenList }

function TFZScreenList.Add: TFormFZScreen;
var
  i : Integer;
begin
  Result := TFormFZScreen.Create(FOwner);
  inherited Add(Result);
//  Result.MonitorIndex := Count-1;

  i := 0;
  if Screen.MonitorCount>1 then
    i := 1;
  Result.Left := Screen.Monitors[i].Left;
  Result.Top :=Screen.Monitors[i].Top;
  Result.Width:=Screen.Monitors[i].Width;
  Result.Height:=Screen.Monitors[i].Height;

  Result.Show;

end;

constructor TFZScreenList.Create;
begin
  inherited Create;
  FOwner := AOwner;
end;

destructor TFZScreenList.Destroy;
begin
  FOwner := nil;
  inherited Destroy;
end;

function TFZScreenList.Get(Index: Integer): TFormFZScreen;
begin
  Result := inherited Get(Index);
end;

procedure TFZScreenList.Notify(Ptr: Pointer; Action: TListNotification);
begin
  if Action = lnDeleted then
    TFormFZScreen(Ptr).Free
  else
    inherited;

end;

procedure TFZScreenList.Put(Index: Integer; const Value: TFormFZScreen);
begin
  inherited Put(Index, Value);
end;

end.
